home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks95 / Aaron 1.0b3.sit / Aaron 1.0b3 / Aaron Source / CDEF and Patches / CDEF.c next >
Text File  |  1995-06-24  |  8KB  |  286 lines

  1. /*    Aaron © 1995 Gregory D. Landweber, ALL RIGHTS RESERVED    */
  2.     
  3. #include "CDEF.h"
  4. #ifndef __powerc
  5. #include <A4Stuff.h>
  6. #endif
  7.  
  8. /*Boolean UseTinges ( RGBColor theColors[] )
  9. {
  10.     return ( Color2Index( theColors + iTingeLight ) !=
  11.              Color2Index( theColors + iTingeDark ) ) &&
  12.            ( Color2Index( theColors + iHiliteLight) !=
  13.              Color2Index( theColors + iEmbossed  ) );
  14. }
  15.  
  16. void PrepareColors ( ControlHandle theControl, RGBColor theColors[] )
  17. {
  18.     AuxCtlHandle    acHndl;
  19.     CCTabHandle        theTable;
  20.     short            index;
  21.     Byte            colorValues[9][3] = { { cBodyColor,  cFrameColor, 0 },
  22.                                           { cBodyColor,  cFrameColor, 1 },
  23.                                           { cBodyColor,  cFrameColor, 3 },
  24.                                           { cBodyColor,  cFrameColor, 9 },
  25.                                           { cBodyColor,  cFrameColor, 13 },
  26.                                           { cBodyColor,  cFrameColor, 15 },
  27.                                           { cBodyColor,  cTextColor,  15 },
  28.                                           { cTingeLight, cTingeDark,  0 },
  29.                                           { cTingeLight, cTingeDark,  4 } };              
  30.     
  31.     GetAuxCtl ( theControl, &acHndl);
  32.     theTable = (*acHndl)->acCTable;
  33.     for ( index = 0; index <= 6; index++ )
  34.         GetRGBColor ( theTable, theColors + index, colorValues[index][0], colorValues[index][1], colorValues[index][2] );
  35.  
  36.     // Get tinges from default "cctb"
  37.     GetAuxCtl ( nil, &acHndl);
  38.     theTable = (*acHndl)->acCTable;
  39.     for ( index = 7; index <= 8; index++ )
  40.         GetRGBColor ( theTable, theColors + index, colorValues[index][0], colorValues[index][1], colorValues[index][2] );
  41. }
  42. */
  43. void GetPartColor ( CTabPtr theTable, RGBColor *theColor, short part )
  44. {
  45.     short    temp = (theTable)->ctSize;
  46.     
  47.     while ( ( (theTable)->ctTable[temp].value != part ) && temp-- );
  48.     if ( temp < 0 )
  49.         temp = 0;
  50.     *theColor = (theTable)->ctTable[temp].rgb;
  51. }
  52. /*
  53. void GetRGBColor ( CCTabHandle theTable, RGBColor *theColor, short backPart, short forePart, short shade)
  54. {
  55.     RGBColor    foreColor, backColor;
  56.     
  57.     GetPartColor ( (CTabPtr)*theTable, &foreColor, forePart );
  58.     GetPartColor ( (CTabPtr)*theTable, &backColor, backPart );
  59.  
  60.     theColor->red    = ( (long)foreColor.red   - (long)backColor.red   ) * shade / 15 + backColor.red;
  61.     theColor->green    = ( (long)foreColor.green - (long)backColor.green ) * shade / 15 + backColor.green;
  62.     theColor->blue    = ( (long)foreColor.blue  - (long)backColor.blue  ) * shade / 15 + backColor.blue;
  63. }
  64. */
  65. void DoDraw1 ( GregInfo *theInfo, CGrafPtr savePort, CGrafPtr myPort, Boolean onScreen )
  66. {
  67.     short        saveFont, saveSize, saveFace, saveMode;
  68.     RGBColor    theForeColor, theBackColor;
  69.     PenState    thePenState;
  70.     RgnHandle    theRgn;
  71.     short        depth;
  72.     
  73.     DeviceLoopDrawingUPP    drawingProc;
  74.     
  75.     saveFont = myPort->txFont;  saveSize = myPort->txSize;
  76.     saveFace = myPort->txFace;  saveMode = myPort->txMode;    
  77.     GetForeColor (&theForeColor);  GetBackColor (&theBackColor);
  78.     GetPenState (&thePenState);
  79.     
  80.     if ( theInfo->useSysFont ) {
  81.         TextFont (systemFont);
  82.         TextSize (0);
  83.         TextFace (0);
  84.     }
  85.     else {
  86.         TextFont (savePort->txFont);
  87.         TextSize (savePort->txSize);
  88.         TextFace (savePort->txFace);
  89.     }
  90.     PenNormal ();    
  91.  
  92.     RectRgn( theRgn = NewRgn(), &theInfo->theRect );
  93.  
  94.     if ( onScreen ) {
  95.         if ( theInfo->pushButton )
  96.             drawingProc = NewDeviceLoopDrawingProc ( &DrawButton );
  97.         else
  98.             drawingProc = NewDeviceLoopDrawingProc ( &DrawIcon );
  99.         DeviceLoop ( theRgn, drawingProc, (long)theInfo, 0 );
  100.         DisposeRoutineDescriptor ( drawingProc );
  101.     }
  102.     else {
  103.         if ( (savePort->portVersion & 0xC000) == 0xC000 )
  104.             depth = (*savePort->portPixMap)->pixelSize;
  105.         else
  106.             depth = 1;
  107.         if ( theInfo->pushButton )
  108.             DrawButton ( depth, 0, nil, theInfo );
  109.          else
  110.             DrawIcon  ( depth, 0, nil, theInfo );
  111.     }
  112.  
  113.     DisposeRgn( theRgn );
  114.     
  115.     TextFont (saveFont);  TextSize (saveSize);
  116.     TextFace (saveFace);  TextMode (saveMode);
  117.     RGBForeColor (&theForeColor);  RGBBackColor (&theBackColor);
  118.     SetPenState (&thePenState);
  119. }
  120.  
  121. void DoDraw ( GregInfo *theInfo )
  122. {
  123.     Boolean        colorPort, onScreen;
  124.     CGrafPtr    savePort, wPort;
  125.     Ptr            BaseAddr;
  126.     Point        globalPt;
  127.     RgnHandle    newClip, oldClip;
  128.     
  129.     CQDProcs    newProcs;
  130.     CQDProcsPtr    saveProcs;
  131.     long        *new, *old;
  132.     short        temp;
  133.     
  134.     long         lRefCon;
  135.     short        editField;
  136.     TEHandle    textH;
  137. //    short        pnVisSave;
  138.     
  139.     StringPtr    curApName = LMGetCurApName();
  140.     
  141. //    SetPort ( (*theInfo->theControl)->contrlOwner );
  142.     
  143.     GetPort ( (GrafPtr *)&savePort );
  144.     colorPort = ( (savePort->portVersion & 0xC000) == 0xC000 );
  145.     
  146.     if ( savePort->rgnSave ) {
  147.         if ( theInfo->pushButton )
  148.             FrameRoundRect ( &theInfo->theRect, Radius, Radius );
  149.         else
  150.             FrameRect ( &theInfo->theRect );
  151.         return;
  152.     }
  153.  
  154.     if ( ( ((long *)curApName)[1] != 'Edit' )
  155.          && !RectInRgn (&theInfo->theRect, savePort->visRgn) ) {
  156.         return;
  157.     }
  158.  
  159.     BaseAddr = ((GrafPtr)savePort)->portBits.baseAddr;
  160.     if ( colorPort )
  161.         BaseAddr = (*(PixMapHandle)BaseAddr)->baseAddr;
  162.         
  163.     onScreen = ( BaseAddr == LMGetScrnBase() );
  164.     
  165.     if ( /* savePort->picSave || */ colorPort || !onScreen )
  166.         DoDraw1 ( theInfo, savePort, savePort, onScreen );
  167.     else {
  168.         SetPt ( &globalPt, 0, 0 );
  169.         LocalToGlobal ( &globalPt );
  170.         OffsetRect ( &theInfo->theRect, globalPt.h, globalPt.v );
  171.         SectRgn ( savePort->visRgn, savePort->clipRgn, newClip = NewRgn() );
  172.         OffsetRgn ( newClip, globalPt.h, globalPt.v );
  173.         GetCWMgrPort ( &wPort );
  174.         SetPort ( (GrafPtr)wPort );
  175.         GetClip ( oldClip = NewRgn() );
  176.         SetClip ( newClip );
  177.         
  178.         old = (long *)savePort->grafProcs;
  179.         if ( old ) {
  180.             textH = ((DialogPeek)wPort)->textH;
  181.             ((DialogPeek)wPort)->textH = ((DialogPeek)savePort)->textH;
  182.             editField = ((DialogPeek)wPort)->editField;
  183.             ((DialogPeek)wPort)->editField = ((DialogPeek)savePort)->editField;
  184.             SetStdCProcs ( &newProcs );
  185.             saveProcs = wPort->grafProcs;
  186.             new = (long *)&newProcs;
  187.             for ( temp = 0; temp <= 12; temp++ )
  188.                 if ( old[temp] )
  189.                     new[temp] = old[temp];
  190.             wPort->grafProcs = &newProcs;
  191.             lRefCon = GetWRefCon ( (WindowPtr)wPort );
  192.             SetWRefCon ( (WindowPtr)wPort, GetWRefCon ( (WindowPtr)savePort ) );
  193.         }
  194.         
  195. //        pnVisSave    = wPort->pnVis;
  196. //        wPort->pnVis = savePort->pnVis;
  197.         
  198.         DoDraw1 ( theInfo, savePort, wPort, onScreen );
  199.         
  200. //        wPort->pnVis = pnVisSave;
  201.         
  202.         if ( old ) {
  203.             ((DialogPeek)wPort)->textH = textH;
  204.             ((DialogPeek)wPort)->editField = editField;
  205.             wPort->grafProcs = saveProcs;
  206.             SetWRefCon ( (WindowPtr)wPort, lRefCon );
  207.         }
  208.         
  209.         SetClip ( oldClip );
  210.         DisposeRgn ( oldClip );
  211.         DisposeRgn ( newClip );
  212.         SetPort ( (GrafPtr)savePort );
  213.     }
  214. }
  215.  
  216. pascal long main ( short varCode, ControlHandle theControl, short msgCode, long msgParam )
  217. {    
  218.     GregInfo    theInfo;
  219.     long        result = 0;
  220.     Boolean        newFolder;
  221.     
  222. #ifndef __powerc    
  223.     long    oldA4 = SetCurrentA4();
  224. #endif
  225.  
  226.     if ( varCode >= 16 ) {
  227.         newFolder = true;
  228.         varCode -= 16;
  229.     }
  230.     else
  231.         newFolder = false;
  232.         
  233.     SetResLoad ( true );    // Since FAXstf leaves this set to false
  234.     
  235.     theInfo.newFolder  = newFolder;
  236.     theInfo.theControl = theControl;
  237.     theInfo.msgParam   = msgParam;
  238.     theInfo.inActive   = (*theControl)->contrlHilite == 255;
  239.     if ( theInfo.inActive )
  240.         theInfo.pushed = 0;
  241.     else
  242.         theInfo.pushed = (*theControl)->contrlHilite != inNone;
  243.     theInfo.theRect              = (*theControl)->contrlRect;
  244.     theInfo.pushButton = (varCode & 0x0007) == pushButProc;
  245.     theInfo.radio      = (varCode & 0x0007) == radioButProc;
  246.     theInfo.useSysFont = !(varCode & useWFont);
  247.     
  248.     switch ( msgCode ) {
  249.         case drawCntl:
  250.             if ( (*theControl)->contrlVis ) {
  251.             //    PrepareColors ( theControl, theInfo.theColors );
  252.                 theInfo.prefs = (GrEGHandle) GetResource ( 'GrEG', 128 );
  253.                 DoDraw ( &theInfo );
  254.             }
  255.             break;
  256.         case testCntl:
  257.             if ( !theInfo.inActive && PtInRect ( *(Point *)&msgParam, &theInfo.theRect ) )
  258.                 result = theInfo.pushButton ? inButton : inCheckBox;
  259.             else
  260.                 result = inNone;
  261.             break;
  262.         case calcCRgns:
  263.             msgParam = msgParam & AddrMask;
  264.         case calcCntlRgn:
  265.         case calcThumbRgn:
  266.             if ( theInfo.pushButton ) {
  267.                 OpenRgn ();
  268.                 FrameRoundRect ( &theInfo.theRect, Radius, Radius );
  269.                 CloseRgn ( (RgnHandle) msgParam );
  270.             }
  271.             else
  272.                 RectRgn( (RgnHandle) msgParam, &theInfo.theRect );
  273.             break;
  274.         case initCntl:
  275.         case dispCntl:
  276.         case posCntl:
  277.         case thumbCntl:
  278.         case dragCntl:
  279.         case autoTrack:
  280.             break;
  281.     }
  282. #ifndef __powerc
  283.     SetA4 ( oldA4 );
  284. #endif
  285.     return result;
  286. }